package com.algorithm.util;

import java.util.Random;

/**
 * Created by mu on 2018/2/5.
 */
public class RandomUtil{
    private static Random random = new Random();

    /**
     * 生成一个随机整数，随机范围left，right
     * @param left
     * @param right
     * @return
     */
    public static int randomInt(int left,int right){
        return random.nextInt(Integer.MAX_VALUE)%(right-left+1)+left;
    }
    /**
     * 生成n个元素的随机数组，随机范围left，right
     * @param n
     * @param left
     * @param right
     * @return
     */
    public static int[] randomArray(int n,int left,int right){

        int [] array=new int[n];
        for (int i = 0; i <array.length ; i++) {
            array[i]=random.nextInt(Integer.MAX_VALUE)%(right-left+1)+left;
        }
        return array;
    }

}
